package com.mi9688.stream;

import java.util.stream.IntStream;

public class Parallel {

    public static void main(String[] args) {
        // 顺序流计算
        long start = System.currentTimeMillis();
        int sum = IntStream.rangeClosed(1, 1000000000).sum();
        long end = System.currentTimeMillis();
        System.out.println("顺序流计算结果：" + sum + "，耗时：" + (end - start) + " 毫秒");

        // 并行流计算
        start = System.currentTimeMillis();
        sum = IntStream.rangeClosed(1, 1000000000).parallel().sum();
        end = System.currentTimeMillis();
        System.out.println("并行流计算结果：" + sum + "，耗时：" + (end - start) + " 毫秒");
    }
}
